#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@author: lyndon
@time Created on 2019/2/23 17:09
@desc
"""
from urlparse3.urlparse3 import parse_url


def getconninfo2(login_str):
    """
    make login_str of db to a dict
    the dict examples :
        -- {'username': 'pyspd_admin', 'database': 'spd_mgr', 'charset': 'utf-8', 'dbtype': 'mysql',
            'host': '192.168.100.161', 'password': 'pyspd_admin_1Q', 'port': '3306'}
    :param login_str:
    :return: dict
    """
    db_infos = parse_url(login_str).__dict__
    db_infos['dbtype'] = db_infos.pop('scheme')
    db_infos['host'] = db_infos.pop('domain')
    db_infos['database'] = db_infos.pop('path').replace('/', '')
    db_infos['charset'] = 'utf8'
    db_infos['port'] = int(db_infos.pop('port'))
    return db_infos


if __name__ == '__main__':
    mysql2hive_task_db = 'mysql://pyspd_admin:pyspd_admin_1Q@192.168.100.161:3306/spd_mgr'
    print(getconninfo2(mysql2hive_task_db))
